from db.mysql import MySQLDB
import time


def is_comment(post_id):
    """
    判断是否已经评论
    :param post_id: 帖子Id
    :return: True/False
    """
    with MySQLDB() as db:
        if db.query("select * from hy_weibo_post_comment where post_id = %s and is_comment = 2", post_id):
            return True
        return False


def comment(params: dict):
    """
    评论
    :param params: 参数
    :return: True/False
    """
    with MySQLDB() as db:
        res = db.execute(
            'insert into hy_weibo_post_comment (uid, post_id, post_content,comment,is_comment,created_at) values (%s, %s, %s, %s, %s, %s)',
            (params['uid'], params['post_id'], params['post_content'], params['comment'], 2,
             time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())))
        if res:
            return True
        return False
